using System;

namespace Copperline.Escriba
{
	/// <summary>
	/// Filters log events based on severity
	/// </summary>
	public class SeverityFilter : FilterBase
	{
		/// <summary>
		/// Creates an instance of class <c>SeverityFilter</c>
		/// </summary>
		/// <param name="trigger">the trigger condition to satisfy</param>
		/// <param name="severity">the severity condition of the filter</param>
		public SeverityFilter( ESeverity severity, ETrigger trigger )
		{
			Trigger = trigger;
			Severity = severity;
		}

		/// <summary>
		/// Returns <c>true</c> if the given severity satisfies the preconfigured
		/// trigger condition, <c>false</c> otherwise.
		/// <seealso cref="ETrigger"/>
		/// <seealso cref="ESeverity"/>
		/// </summary>
		/// <param name="severityOfEntry">the severity to test</param>
		/// <returns></returns>
		public override bool HasRequiredSeverity(ESeverity severityOfEntry )
		{
			switch( Trigger )
			{
				case ETrigger.match:
					return 0 == Severity.CompareTo( severityOfEntry );

				case ETrigger.threshold:
					return 0 >= Severity.CompareTo( severityOfEntry );

				default:
					return false;
			}
		}
	}
}
